package com.factory.test.m3021;

import android.os.Bundle;
import android.os.yx.YxDeviceManager;
import android.util.Log;
import android.widget.CompoundButton;

import androidx.databinding.DataBindingUtil;

import com.factory.test.R;
import com.factory.test.base.BaseTestActivity;
import com.factory.test.base.MyApplication;
import com.factory.test.databinding.ActivityM3021GpioBinding;
import com.factory.test.util.gpio.GpioController;


/**
 * GPIO 输入输出
 */
public class GpioActivity extends BaseTestActivity {

    private ActivityM3021GpioBinding binding;

    private GpioController gpioController;
YxDeviceManager yx;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_m3021_gpio);
yx=YxDeviceManager.getInstance(this);
//        gpioController = MyApplication.getBaseFactoryTest().getDeviceGpioController();
//
//        binding.gpio1.setChecked(gpioController.getIo(1) == 1);
//        binding.gpio2.setChecked(gpioController.getIo(2) == 1);
        binding.gpio1.setChecked((yx.getGpioValue(114)==1));
        binding.gpio2.setChecked((yx.getGpioValue(115)==1));
        binding.gpio1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                yx.setGpioValue(114,isChecked?1:0);
//                Log.d("TAG", "onCheckedChanged: "+yx.getGpioValue(114));

            }
        });

        binding.gpio2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                yx.setGpioValue(115,isChecked?1:0);
//                Log.d("TAG", "onCheckedChanged: "+yx.getGpioValue(115));

            }
        });
    }
}
